<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="admin/common/header::common-head">
    <!--<#include "../common/header.html">-->
</head>
<body>
<!--边栏-->
<!--<#include "../common/nav.html">-->
<div th:replace="admin/common/nav::common-nav" ></div>
<script src="https://cdn.bootcss.com/twitter-bootstrap/3.0.1/js/bootstrap.min.js"></script>

<div class="content-wrapper" style="width: auto">
    <div class="container">
        <div class="row clearfix">
            <div class="col-md-12 column">
                <form role="form" action="/fashionpress/nick/update" enctype="multipart/form-data" method="post" id="form1">
                    <div class="form-group" th:if="${formnick!=null}">
                        <label for="nickId">角色编号:</label><input type="text" name="nickId" id="nickId" size="50" placeholder="50字以内" th:value="${formnick!=null?formnick.nickId:''}" readonly="readonly" style="border: 0">
                    </div>
                    <div class="form-group">
                        <label for="nickName">角色名</label><input type="text" class="form-control" id="nickName" name="nickName" th:value="${formnick!=null?formnick.nickName:''}"/>
                    </div>
                    <div class="form-group">
                        <label>权限</label>
                        <div th:each="role:${rolelist}">
                            <input type="checkbox"  th:value="${role.roleId}" name="role"/><span th:text="${role.roleName}"></span>
                        </div>
                    </div>
                    <div class="form-group">
                        <input type="hidden" name="roles" id="roleId" >
                    </div>
                    <div class="form-group">
                        <button type="submit" class="btn btn-default">提交</button>
                    </div>
                </form>
            </div>
        </div>
    </div>


    <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
    <script type="text/javascript">
        function chk(){
            var obj=document.getElementsByName('roles');
            var s='';
            for(var i=0; i<obj.length; i++){
                if(obj[i].checked) s+=obj[i].value+',';
            }
            alert(s==''?'你还没有选择任何内容！':s);
        }
    </script>
    <script th:inline="javascript">
        $(document).ready(function () {
            //提交表单时的数据拼接
            $("#form1").submit(function () {
                //批量获取数据进行封装
                $rolelist= $("input[name='role']");
                $roleids  = "";
                for (var i = 0;i<$rolelist.length; i++){
                    console.log($rolelist[i].checked);
                    if ($rolelist[i].checked) {
                        $roleids = $roleids+$rolelist[i].value+",";
                    }

                }
                //返回字符串
                $("#roleId").attr("value",$roleids);
                return true;

            })
        });



    </script>
    <script th:inline="javascript">
        $(document).ready(function () {




            $rolelists = $("input[name='role']");
            for (var i=0;i<$rolelists.length;i++){
                if([[${formnick}]]!=null){
                    $nickroles = [[${formnick.roleList}]];
                    for (var j=0;j<$nickroles.length;j++){
                        if ($rolelists[i].value==$nickroles[j].roleId){
                            $rolelists[i].checked=true;
                        }
                    }
                }

            }
            //角色名默认是不能更改的
            if([[${formnick.nickId}]]!=null){
                $("#nickName").attr("readonly","readonly");
            }


        });
    </script>
</div>
<div th:replace="admin/common/footer::common-footer"></div>
</body>
</html>